package o;

import android.app.Activity;
import android.content.Context;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.MainActivity;
import com.huawei.appmarket.R;
import com.huawei.appmarket.framework.startevents.bean.CountryInfo;
import com.huawei.appmarket.framework.startevents.bean.DistStartupResponse;
import com.huawei.appmarket.framework.startevents.protocol.ServiceZoneSwitchActivityProtocol;
import com.huawei.appmarket.framework.startevents.protocol.ServiceZoneSwitchActivityProtocol.Request;
import com.huawei.cloudservice.CloudAccount;
import java.lang.ref.SoftReference;
import java.util.List;
import o.dgw.c;

public class dzs extends dzr<Void, Void> implements IServerCallBack {
    private static long ॱ = 0;
    private boolean ˊ = false;
    private Activity ˋ;
    private long ˏ = 0;

    static class e implements eql {
        private SoftReference<dzs> ॱ;

        public e(dzs o_dzs) {
            this.ॱ = new SoftReference(o_dzs);
        }

        public void ˋ() {
            Logger.ˎ("GLOBAL_START_FLOW", "GrsProcesser onSuccess");
            dzl.ˏ("grs", dzs.ॱ);
            dzs o_dzs = (dzs) this.ॱ.get();
            if (o_dzs != null) {
                o_dzs.ˏॱ();
            }
        }

        public void ˎ(int i) {
            Logger.ˋ("GLOBAL_START_FLOW", "GrsProcesser onFailed code=" + i);
            eok.ˎ().ॱ(20, i, "Failed to access GRS server.");
            if (epv.ᐝ(ContentManager.getInstant().getContext())) {
                evk.ॱ(ContentManager.getInstant().getContext().getString(R.string.connect_server_fail_prompt_toast), 0).ˋ();
            }
            dzl.ˋ("208", "code=" + i);
            dzs o_dzs = (dzs) this.ॱ.get();
            if (o_dzs != null) {
                o_dzs.ˏ();
            }
        }
    }

    protected /* synthetic */ Object ˎ(Object obj) {
        return ॱ((Void) obj);
    }

    public dzs(Activity activity, boolean z) {
        super(z);
        this.ˋ = activity;
    }

    public static void ॱ(ResponseBean responseBean, int i) {
        CountryInfo ʻ = ((StartupResponse) responseBean).ʻ();
        if (ʻ != null) {
            List ˋ = ʻ.ˋ();
            if (CollectCheck.isEmpty(ˋ)) {
                Logger.ˎ("GLOBAL_START_FLOW", "CallFrontFlow countryList is empty.");
                return;
            }
            Logger.ˎ("GLOBAL_START_FLOW", "CallFrontFlow countryList is not empty.");
            dzu.ॱ(ˋ, i);
            return;
        }
        Logger.ˎ("GLOBAL_START_FLOW", "CallFrontFlow countryInfo is empty.");
    }

    public void ˋ(boolean z) {
        this.ˊ = z;
    }

    protected String ॱ() {
        return "CallFrontFlow";
    }

    protected Void ॱ(Void voidR) {
        Logger.ˎ("GLOBAL_START_FLOW", "CallFrontFlow call front");
        if (doo.ˊ(ContentManager.getInstant().getContext())) {
            ˎ();
            ͺ();
        } else {
            Logger.ˎ("GLOBAL_START_FLOW", "CallFrontFlow not has network");
            dzl.ˋ("205", "NETWORK-UNCONNECTED");
            ˏ();
        }
        return null;
    }

    private void ͺ() {
        if (!doo.ˊ(ContentManager.getInstant().getContext())) {
            Logger.ˎ("GLOBAL_START_FLOW", "CallFrontFlow not has network");
            dzl.ˋ("205", "NETWORK-UNCONNECTED");
            ˏ();
        }
        ˎ();
        eqm ˊ = eqk.ˊ();
        if (ˊ == null) {
            Logger.e("GLOBAL_START_FLOW", "grsProcesser is null.");
            dzl.ˋ("208", "ProcesserNull");
            ˏ();
            return;
        }
        ॱ = dgh.ॱ();
        ˊ.ॱ(new e(this));
    }

    private void ˏॱ() {
        cvt ˎ = cvv.ˎ();
        ˎ.setServiceType_(dgm.ˎ(this.ˋ));
        if (this.ˋ instanceof MainActivity) {
            ˎ.ˊ(1);
        } else {
            ˎ.ˊ(0);
        }
        if (dzp.ˏ().ˎ()) {
            ˎ.ʼ(1);
            ˎ.ˋ(eqp.ͺ());
        }
        this.ˏ = dgh.ॱ();
        cfw.ˎ(ˎ, new dgw(this.ˋ, c.INVOKE, this, new dgv(this) {
            final /* synthetic */ dzs ˏ;

            {
                this.ˏ = r1;
            }

            public void ˎ() {
                this.ˏ.ˋ();
            }
        }));
    }

    public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
    }

    public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
        DistStartupResponse distStartupResponse = (DistStartupResponse) responseBean;
        Logger.ˎ("GLOBAL_START_FLOW", "CallFrontFlow responseCode=" + distStartupResponse.getResponseCode() + " returnCode=" + distStartupResponse.getRtnCode_() + " isCheckMustLogin=" + this.ˊ);
        dyq.ˋ("");
        if (distStartupResponse.getResponseCode() == 0 && distStartupResponse.getRtnCode_() == 0) {
            dzl.ˏ("front", this.ˏ);
            distStartupResponse.ˎ(o_cvu);
            dil.ˏ().ˎ(dil.ˏ().ॱ(distStartupResponse));
            RoamDataManager.build().ˎ(distStartupResponse.ʿ());
            dzv.ˊ(true);
            if (this.ˊ) {
                int ˊॱ = distStartupResponse.ˊॱ();
                int ˊ = distStartupResponse.ˊ();
                if (1 != ˊॱ && 1 == ˊ) {
                    ˏ(o_cvu, responseBean);
                    return;
                } else if (dzp.ˏ().ˎ()) {
                    Logger.ˎ("GLOBAL_START_FLOW", "CallFrontFlow retryFlag and setRetryFlag=false.");
                    dzp.ˏ().ˏ(false);
                    ˎ();
                    dzp.ˏ().ˎ(this.ˋ, new Runnable(this) {
                        final /* synthetic */ dzs ˏ;

                        {
                            this.ˏ = r1;
                        }

                        public void run() {
                            this.ˏ.nextFlow(new dzx(this.ˏ.ˋ, this.ˏ.ˊ()));
                            this.ˏ.ˊ(null);
                        }
                    }, new Runnable(this) {
                        final /* synthetic */ dzs ॱ;

                        {
                            this.ॱ = r1;
                        }

                        public void run() {
                            Logger.ˎ("GLOBAL_START_FLOW", "CallFrontFlow Cancelled by user.");
                            eok.ˎ().ॱ(40, 0, "Cancelled by user.");
                            this.ॱ.ˋ();
                        }
                    });
                    return;
                } else {
                    nextFlow(new dzx(this.ˋ, ˊ()));
                    ˊ(null);
                    return;
                }
            }
            ˏ(o_cvu, responseBean);
            if (dgr.ˋ().ॱ()) {
                cvt o_dgt = new dgt(dgr.ˋ().ˎ());
                o_dgt.setServiceType_(dgr.ˋ().ˏ());
                cfw.ˎ(o_dgt, new dgo("CallFrontFlow"));
                return;
            }
            return;
        }
        eok.ˎ().ॱ(30, distStartupResponse.getResponseCode(), "Failed to access STORE server,  responseCode=" + distStartupResponse.getResponseCode() + " returnCode=" + distStartupResponse.getRtnCode_());
        if (distStartupResponse.getResponseCode() == 3) {
            evk.ॱ(ContentManager.getInstant().getContext().getString(R.string.no_available_network_prompt_title), 0).ˋ();
        } else {
            evk.ॱ(ContentManager.getInstant().getContext().getString(R.string.connect_server_fail_prompt_toast), 0).ˋ();
        }
        dzl.ˋ("209", "code=" + distStartupResponse.getResponseCode() + "returnCode=" + distStartupResponse.getRtnCode_());
        ˏ();
    }

    private void ˏ(BaseRequest o_cvu, ResponseBean responseBean) {
        StartupResponse startupResponse = (StartupResponse) responseBean;
        if (1 != startupResponse.ˊ()) {
            Logger.ˎ("GLOBAL_START_FLOW", "CallFrontFlow not support service");
            int ॱ = ccz.ॱ();
            if (o_cvu instanceof cvt) {
                ॱ = ((cvt) o_cvu).getServiceType_();
            }
            ॱ(responseBean, ॱ);
            CloudAccount ˊ = eos.ˊ();
            if (!UserSession.getInstance().isLoginSuccessful() || ˊ == null) {
                UserSession.getInstance().setLoginSuccessful(false);
                eop.ˎ(UserSession.getInstance());
                dzv.ˊ(false);
                nextFlow(new dzx(this.ˋ, ˊ()));
                ˊ(null);
                return;
            }
            ˊॱ();
            return;
        }
        eqo.ॱ().ˎ(dgm.ˎ(this.ˋ), new b(o_cvu, responseBean));
        if (1 != startupResponse.ˊॱ()) {
            dyq.ˋ(eqp.ॱ());
        }
        ˊ(null);
    }

    private void ˊॱ() {
        String str;
        String str2 = null;
        Context ˋ = ContentManager.getInstant().getContext();
        int ˎ = dgm.ˎ(this.ˋ);
        if (this.ˋ == null) {
            Logger.e("CallFrontFlow", "goServiceZoneSwitchActivity error,activity is null");
            str = null;
        } else if (ˎ == 17) {
            str = ˋ.getString(R.string.kidschannel_not_support);
            str2 = ˋ.getString(R.string.kidschannel_app_name);
        } else if (ˎ == 18) {
            str = ˋ.getString(R.string.educhannel_not_support);
            str2 = ˋ.getString(R.string.educhannel_app_name);
        } else {
            str = null;
        }
        cjo serviceZoneSwitchActivityProtocol = new ServiceZoneSwitchActivityProtocol();
        serviceZoneSwitchActivityProtocol.ॱ(new Request());
        serviceZoneSwitchActivityProtocol.ॱ().ˋ(str);
        serviceZoneSwitchActivityProtocol.ॱ().ˊ(str2);
        serviceZoneSwitchActivityProtocol.ॱ().ˏ(ˎ);
        cjm o_cjm = new cjm("servicezoneswitch.activity", serviceZoneSwitchActivityProtocol);
        if (this.ˋ == null) {
            o_cjm.ॱ(ˋ).setFlags(268435456);
            cjk.ˎ().ˋ(ˋ, o_cjm);
        } else {
            cjk.ˎ().ˋ(this.ˋ, o_cjm);
        }
        ˋ();
    }
}
